package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-11-28 23:40
 */
public class IsSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root==null) return true;
        return compare(root.left,root.right);
    }

    private boolean compare(TreeNode left, TreeNode right) {
        if (left==null&&right==null) return true;
        if (left==null) return false;
        if (right==null) return false;
        if (left.val!=right.val) return false;
        return compare(left.left,right.right)&&compare(left.right,right.left);
    }

}
